import {Component, HostListener, Injector} from '@angular/core';
import {Router} from '@angular/router';
import {Global} from "./global.component";
import Modal, {ModalData, RzMessage} from "@core/Tool/Modal";
import {AuthService} from "@core/auth/AuthService";
import Store from "@app/shared/Store";

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrl: './app.component.scss',
  providers: [
  ]
})
export class AppComponent {
  modalData: ModalData = new ModalData({message: '',visible: false});

  constructor(private router: Router, private global: Global,
              private authService: AuthService) {
    Modal.RzModalEvent = (data: ModalData) => {
      this.modalData = data;
    }
    Store.global = this.global;
    // authService.clearToken()
    this.authorized()
    this.test()
  }

  authorized() {
    // console.log('AppComponent')
    //检测是否已经登录,未登录则跳转到登录页面
    if (AuthService.token) {
      this.router.navigate(['/home']).then(r => {});
    }else
      this.router.navigate(['/login']).then(r => {});
  }

  test() {
  }

  title = 'fAngular';

  goTo(product: string) {
    this.router.navigate(['/' + product]).then(r => {
    });
  }
  @HostListener('window:resize', ['$event'])
  onResize(event:Event) {
    const target:Window = event.target as Window;
    Store.WHPercentage.height = target.innerHeight / 1080;
    Store.WHPercentage.width = target.innerWidth - Store.WHPercentage.height * 1920;
    console.log('onResize')
  }
}
